package geppetto.phraseHMM.phraseExtraction.phraseAccepter;

import geppetto.cat.alignments.AbstractAlignmentsCache;
import geppetto.cat.alignments.Alignment;
import geppetto.cat.alignments.AlignmentsCache;
import geppetto.cat.alignments.AlignmentsSet;
import geppetto.phraseHMM.phraseExtraction.extractedphrase.ExtractedPhrasePair;

import java.io.IOException;

public class NoSurePointConflictAccepter extends AbstractPhraseAccepter {

	AlignmentsSet _alignments;
	AbstractAlignmentsCache _cache;

	public NoSurePointConflictAccepter(AlignmentsSet a) {
		_alignments = a;
		_cache = new AbstractAlignmentsCache(a){
			@Override
		public boolean hasPosition(Alignment al, int indexSrc, int indexTar) {
				return al.isSure(indexSrc, indexTar);
			}
		};
	}

	public boolean acceptPhrase(int sentenceNumber, byte sentenceSource,
			int[] foreingSentence, int[] sourceSentence, int sourceStartPos,
			int sourceEndPos, int foreignStartPos, int foreignEndPos,
			double score) {
		
		if(!_cache.hasConflits(sentenceNumber, sourceStartPos, sourceEndPos, foreignStartPos, foreignEndPos)){
			return true;
		}
		
		return false;
	}


	@Override
	public boolean acceptPhrase(ExtractedPhrasePair epp) {
		int sentenceNumber = epp.getSentenceNumber();
		int foreignEndPos = epp.getForeignEndPos();
		int foreignStartPos = epp.getForeignStartPos();
		int sourceEndPos = epp.getSourceEndPos();
		int sourceStartPos = epp.getSourceStartPos();
		
		if(!_cache.hasConflits(sentenceNumber, sourceStartPos, sourceEndPos, foreignStartPos, foreignEndPos)){
			return true;
		}
		
		return false;
	}

}
